package com.sinosoft.front;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;


import com.hangxin.basic.util.MyTimeUtil;

import org.apache.log4j.Logger;


import com.sinosoft.front.dto.CarQueryService.out.xsd.CarQueryInfo;
import com.sinosoft.front.dto.common.xsd.IinsuranceExtensionEhm;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestEhm;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestExtensionEhm;
import com.sinosoft.front.dto.proposalSaveTp.out.xsd.Applicant;
import com.sinosoft.front.dto.proposalSaveTp.out.xsd.CarOwner;
import com.sinosoft.front.dto.proposalSaveTp.out.xsd.InsuredData;
import com.sinosoft.front.dto.proposalSaveTp.out.xsd.Main;
import com.sinosoft.front.dto.vehicleModelQuery.out.xsd.VehicleModelData;
import com.sinosoft.front.dto.xsd.CarQueryRequest;
import com.sinosoft.front.dto.xsd.CarQueryResponse;
import com.sinosoft.front.dto.xsd.ProposalSaveRequest;
import com.sinosoft.front.dto.xsd.ProposalSaveResponse;
import com.sinosoft.front.dto.xsd.VehicleModelQueryRequest;
import com.sinosoft.front.dto.xsd.VehicleModelQueryResponse;
import com.sinosoft.front.service.CarQueryServicePortType;
import com.sinosoft.front.service.CarQueryServicePortTypeProxy;
import com.sinosoft.front.service.ProposalSaveServicePortType;
import com.sinosoft.front.service.ProposalSaveServicePortTypeProxy;
import com.sinosoft.front.service.VehicleModelQueryServicePortType;
import com.sinosoft.front.service.VehicleModelQueryServicePortTypeProxy;


public class ProposalSaveTest {
	
	static Logger logger = Logger.getLogger(ProposalSaveTest.class);
	public static void main(String[] args) throws RemoteException, ServiceException, MalformedURLException {
		//调用服务器端方法
		ProposalSaveServicePortTypeProxy proxy = new ProposalSaveServicePortTypeProxy();
		proxy.setEndpoint("http://proxy.tuxing51.com/frontServiceCenter/services/ProposalSaveService?wsdl");
		ProposalSaveServicePortType portType = proxy.getProposalSaveServicePortType();
		
		logger.info("========投保单保存服务==========");
		//请求头信息
		ProposalSaveRequest request = new ProposalSaveRequest();
		TxInsuranceRequestEhm requestEhm = new TxInsuranceRequestEhm();

		requestEhm.setTransExeDate(MyTimeUtil.getCurrentDate());//交易日期
		requestEhm.setTransExeTime(MyTimeUtil.getCurrentTime());//交易时间

		request.setTxInsuranceRequestEhm(requestEhm);
		
		requestEhm.setIinsuranceExtensionEhm(new IinsuranceExtensionEhm());
	
		//请求头数据
		TxInsuranceRequestExtensionEhm extensionEhm = new TxInsuranceRequestExtensionEhm();
		extensionEhm.setOperator("HN1_Test");//用户名
		extensionEhm.setOperatorKey("123456");//密码
		request.setTxInsuranceRequestExtensionEhm(extensionEhm );
		
		Main main = new Main();//主表信息
		main.setBusinessSource("2");//业务来源
		//main.setComCode("0");//归属机构  不知道填啥，暂时为0
		main.setPolicySort("HN1");//系统来源标识

		main.setProvisonalNo("905112017410522000038");//试算单号 ，“费改保费计算服务”入参和出参都有

		main.setAgentCode("1234567899");//代理点代码和代理人代码一样？
		//main.setFranchiserCode("4105979018"); 接口里没有这个字段但是文档里面有
		main.setRelationFlag("2"); //关联单标识 
		main.setCarCheckStatus("4");//验车情况 1.需验车 2.免验车 3.已验车
		main.setCityAreaCode("410500"); //城市代码

		Applicant applicant = new Applicant();//投保人信息
		applicant.setAppliName("吴静菡");//投保人信息
		applicant.setInsuredNature("3");//客户性质 3-自然人 4-法人标志
		applicant.setIdentifyType("01");//证件类型 01身份证
		applicant.setIdentifyNumber("410725199412015720");//证件号
		
		InsuredData insuredData = new InsuredData();//被保人信息
		insuredData.setInsuredName("吴静菡");//被保险人名
		insuredData.setInsuredNature("3");//客户性质 3-自然人 4-法人标志
		insuredData.setIdentifyType("01");//证件类型 01身份证
		insuredData.setIdentifyNumber("410725199412015720");//证件号
		
		CarOwner carOwner = new CarOwner();	//车主信息
		carOwner.setInsuredName("吴静菡"); //车主姓名
		carOwner.setInsuredNature("3");//客户性质 3-自然人 4-法人标志
		carOwner.setIdentifyType("01");//证件类型 01身份证
		carOwner.setIdentifyNumber("410725199412015720");//证件号
		//入口参数
		request.setMain(main);   //主表信息
		
		request.setApplicant(applicant); //投保人信息
		request.setInsuredData(insuredData);//被保人信息
		request.setCarOwner(carOwner);   //车主信息	
		logger.info("输入信息：");
		logger.info("主表信息:"+request.getMain());
		logger.info("业务来源："+main.getBusinessSource());
		logger.info("系统来源标识："+main.getPolicySort());
		logger.info("试算单号 ，“费改保费计算服务”入参和出参都有："+main.getProvisonalNo());
		logger.info("代理点代码和代理人代码一样？："+main.getAgentCode());
		logger.info("关联单标识 ："+main.getRelationFlag() );
		logger.info("验车情况 1.需验车 2.免验车 3.已验车："+main.getCarCheckStatus());
		logger.info("城市代码："+main.getCityAreaCode() );		
		
		logger.info("投保人信息:"+request.getApplicant());
		logger.info("投保人信息："+applicant.getAppliName());
		logger.info("客户性质 3-自然人 4-法人标志："+applicant.getInsuredNature());
		logger.info("证件类型 01身份证："+applicant.getIdentifyType());
		logger.info("证件号："+applicant.getIdentifyNumber());

		logger.info("车主信息:"+request.getCarOwner());
		logger.info("车主姓名："+carOwner.getInsuredName() );
		logger.info("客户性质 3-自然人 4-法人标志："+carOwner.getInsuredNature());
		logger.info("证件类型 01身份证："+carOwner.getIdentifyType());
		logger.info("证件号："+carOwner.getIdentifyNumber());

		logger.info("被保人信息:"+request.getInsuredData());
		logger.info("被保险人名："+insuredData.getInsuredName());
		logger.info("客户性质 3-自然人 4-法人标志："+insuredData.getInsuredNature());
		logger.info("证件类型 01身份证："+insuredData.getIdentifyType());
		logger.info("证件号："+insuredData.getIdentifyNumber());

		logger.info("返回信息：");
		//调用投保单保存服务接口
		ProposalSaveResponse response = portType.proposalSave(request);
		System.out.println(response.getTxInsuranceResponseEhm().getTransResultEhm().getResultCode());
		System.out.println(response.getTxInsuranceResponseEhm().getTransResultEhm().getResultInfoDesc());
		System.out.println(response.getTxInsuranceResponseEhm().getTransResultEhm().getErrorNo());
		logger.info("返回状态："+response.getTxInsuranceResponseEhm().getTransResultEhm().getResultCode());
		logger.info("返回内容："+response.getTxInsuranceResponseEhm().getTransResultEhm().getResultInfoDesc());
		logger.info("返回出错码："+response.getTxInsuranceResponseEhm().getTransResultEhm().getErrorNo());
		//获取返回信息
		
			System.out.println("系统来源标识:"+response.getPolicySort());
			System.out.println("成功标识:"+response.getSucessFlag());
			System.out.println("失败原因:"+response.getErrorMessage());
		
		logger.info("系统来源标识:"+response.getPolicySort()+"，成功标识："+response.getSucessFlag()+"，失败原因："+response.getErrorMessage());
		logger.info("-------------------------------------------");

	}

}